<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>检索一个元素</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="memcached.flush.html">Memcached::flush</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="memcached.getallkeys.html">Memcached::getAllKeys</a></div>
 <div class="up"><a href="class.memcached.html">Memcached</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="memcached.get" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Memcached::get</h1>
  <p class="verinfo">(PECL memcached &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">Memcached::get</span> &mdash; <span class="dc-title">检索一个元素</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-memcached.get-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>Memcached::get</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$key</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.callback" class="type callback">callback</a></span> <code class="parameter">$cache_cb</code></span>
   [, <span class="methodparam"><span class="type">float</span> <code class="parameter reference">&$cas_token</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>Memcached::get()</strong></span>返回之前存储在<em><code class="parameter">key</code></em>下的元素。如果元素被找到，并且提供
   了<em><code class="parameter">cas_token</code></em>参数， 这个参数（译注：这个参数在函数定义中是引用参数，用来传出元素的版本标记，原理
   可以查阅乐观锁资料）将会包含该元素的CAS标记值。关于CAS标记值的使用，请查看<span class="methodname"><a href="memcached.cas.html" class="methodname">Memcached::cas()</a></span>的说明。
   另外，可以通过<em><code class="parameter">cache_cb</code></em>参数设置<a href="memcached.callbacks.html" class="link">Read-through caching callback</a>。
  </p>
  <p class="para">
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-memcached.get-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">key</code></em></dt>

     <dd>

      <p class="para">
       要检索的元素的key。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">cache_cb</code></em></dt>

     <dd>

      <p class="para">
       通读缓存回掉函数或<strong><code>NULL</code></strong>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">cas_token</code></em></dt>

     <dd>

      <p class="para">
       检索的元素的CAS标记值。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-memcached.get-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回存储在服务端的元素的值或者在其他情况下返回<strong><code>FALSE</code></strong>。
   如果key不存在，<span class="methodname"><a href="memcached.getresultcode.html" class="methodname">Memcached::getResultCode()</a></span>返回<strong><code>Memcached::RES_NOTFOUND</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-memcached.get-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4345">
    <p><strong>Example #1 <span class="function"><strong>Memcached::get()</strong></span> 示例 #1</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">100</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
int(100)
</pre></div>
    </div>
   </div>
   <div class="example" id="example-4346">
    <p><strong>Example #2 <span class="function"><strong>Memcached::get()</strong></span> 示例 #2</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /><br />if&nbsp;(!(</span><span style="color: #0000BB">$ip&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'ip_block'</span><span style="color: #007700">)))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResultCode</span><span style="color: #007700">()&nbsp;==&nbsp;</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">::</span><span style="color: #0000BB">RES_NOTFOUND</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ip&nbsp;</span><span style="color: #007700">=&nbsp;array();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'ip_block'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$ip</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;log&nbsp;error&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-memcached.get-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="memcached.getbykey.html" class="methodname" rel="rdfs-seeAlso">Memcached::getByKey()</a> - 从特定的服务器检索元素</span></li>
    <li class="member"><span class="methodname"><a href="memcached.getmulti.html" class="methodname" rel="rdfs-seeAlso">Memcached::getMulti()</a> - 检索多个元素</span></li>
    <li class="member"><span class="methodname"><a href="memcached.getdelayed.html" class="methodname" rel="rdfs-seeAlso">Memcached::getDelayed()</a> - 请求多个元素</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="memcached.flush.html">Memcached::flush</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="memcached.getallkeys.html">Memcached::getAllKeys</a></div>
 <div class="up"><a href="class.memcached.html">Memcached</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
